//package com.zx._10_设计模式.行为型模式.观察者模式.demo3;
//
//
//import java.util.Map;
//import java.util.concurrent.ExecutorService;
//import java.util.concurrent.Executors;
//import java.util.concurrent.Flow;
//import java.util.concurrent.SubmissionPublisher;
//
//public class Sender implements Flow.Publisher {
//
//    private SubmissionPublisher<Object> publisher;
//
//    Sender() {
//        ExecutorService pool = Executors.newFixedThreadPool(5);
//        publisher = new SubmissionPublisher<>(pool, Flow.defaultBufferSize());
//    }
//
//    public static void main(String[] args) {
//        Sender sender = new Sender();
//
//        Receiver receiver1 = new Receiver(1);
//        sender.subscribe(receiver1);
//
//        Receiver receiver2 = new Receiver(2);
//        sender.subscribe(receiver2);
//
//        for (int i = 0; i < 10; i++) {
//            sender.send(Map.of(i + "", "这是第" + i + "条消息"));
//        }
//    }
//
//    @Override
//    public void subscribe(Flow.Subscriber subscriber) {
//        getPublisher().subscribe(subscriber);
//    }
//
//    public SubmissionPublisher<Object> getPublisher() {
//        return publisher;
//    }
//
//    public void send(Map<String, Object> map) {
//        System.out.println("publish send msg : " + map);
//        getPublisher().submit(map);
//    }
//}
